<template>
  <div id="globalHeader">
    <a-row :wrap="false">
      <a-col flex="200px">
        <div class="title-bar">
          <img class="logo" src="../assets/logo.png" alt="logo" />
        </div>
      </a-col>
      <a-col flex="auto">
        <a-menu
          v-model:selectedKeys="current"
          mode="horizontal"
          :items="items"
          @click="doMenuClick"
        />
      </a-col>
      <a-col flex="80px">
        <div class="user-login-status">
          <div v-if="loginUserStore.loginUser.id">
            {{ loginUserStore.loginUser.username ?? "无名" }}
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script lang="ts" setup>
import { h, ref } from "vue";
import { CrownOutlined, HomeOutlined } from "@ant-design/icons-vue";
import { MenuProps } from "ant-design-vue";
import { useRouter } from "vue-router";
import { useLoginUserStore } from "@/store/useLoginUserStore";

const loginUserStore = useLoginUserStore();

const router = useRouter();
// 点击菜单后的路由跳转事件
const doMenuClick = ({ key }: { key: string }) => {
  router.push({
    path: key,
  });
};

const current = ref<string[]>(["mail"]);
// 监听路由变化，更新当前菜单选中状态
router.afterEach((to, from, failure) => {
  current.value = [to.path];
});

const items = ref<MenuProps["items"]>([
  {
    key: "/",
    icon: () => h(HomeOutlined),
    label: "联合库UNHub",
    title: "联合库UNHub",
  },
  {
    key: "/user/login",
    label: "用户登录",
    title: "用户登录",
  },
  {
    key: "/user/register",
    label: "用户注册",
    title: "用户注册",
  },
  {
    key: "/news",
    label: "Global News",
    title: "Global News",
  },
  {
    key: "/company",
    label: "组织架构",
    title: "组织架构",
  },
  {
    key: "/approve",
    label: "提交宝贵建议",
    title: "提交宝贵建议",
  },
]);
</script>

<style scoped>
#globalHeader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
}
.title-bar {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.title {
  color: black;
  font-size: 18px;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
/*选中字体颜色*/
:deep(
    .ant-menu-light.ant-menu-horizontal > .ant-menu-item-selected,
    .ant-menu-light.ant-menu-horizontal > .ant-menu-submenu-selected
  ) {
  color: #c33c31;
}
/*选中下滑横线*/
:deep(
    .ant-menu-light.ant-menu-horizontal > .ant-menu-item-selected::after,
    .ant-menu-light.ant-menu-horizontal > .ant-menu-submenu-selected::after
  ) {
  border-bottom-color: #c33c31;
}
/*滑动下划线颜色*/
:deep(
    .ant-menu-light.ant-menu-horizontal > .ant-menu-item:hover::after,
    .ant-menu-light.ant-menu-horizontal > .ant-menu-submenu-active::after
  ) {
  border-bottom-color: #c33c31;
}
</style>
